<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../../vue.js"></script>
</head>

<body>
  <div id="app">
    <!-- 动态组件 -->
    <!-- 数据驱动视图 -->
    <keep-alive>
      <component v-bind:is="getCurrentTap"></component>
    </keep-alive>
    <button v-for="t in tabs" @click="handleChange(t)">
      {{t}}
    </button>

  </div>

  <script>

    Vue.component('tap-position', {
      template: `<div style="height:500px; overflow-y:scroll;">
      <p>position</p>
      <p>position</p>
      <p>position</p>
      <p>position</p>
      <p>position</p>
      <p>position</p>
      <p>position</p>
      <p>position</p>
      <input type="checkbox"/>
      <p>position</p>
      <p>position</p>
      <p>position</p>
      <p>position</p>
      <p>position</p>
      <p>position</p>
      <p>position</p>
      <p>position</p>
      <p>position</p>
      <p>position</p>
      <p>position</p>
      <p>position</p>
      <p>position</p>
      <p>position</p>
      <p>position</p>
      <p>position</p>
      
      </div>`
    })



    Vue.component('tap-search', {
      template: '<div>search</div>'
    })



    Vue.component('tap-profile', {
      template: '<div>profile</div>'
    })



    var vm = new Vue({
      el: "#app",
      data: {
        currentTap: 'position',
        tabs: ['position', 'search', 'profile']
      },
      computed: {
        getCurrentTap() {
          return 'tap-' + this.currentTap;
        }
      },
      methods: {
        handleChange(tabs) {
          this.currentTap = tabs;
        }
      }
    })
  </script>

</body>

</html>